package com.soulkun.smarthome.ui.main.personal.viewmodel

import androidx.databinding.ObservableArrayList
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import com.amap.api.maps.model.LatLng
import com.soulkun.smarthome.logic.model.AddressModel
import com.soulkun.smarthome.logic.model.FamilyModel
import com.soulkun.smarthome.logic.model.RoomModel
import com.soulkun.smarthome.logic.repository.ApiRepository
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import soulkun.library.mvvm.adapter.clearAndAddAll

class AppMainPersonalFamilyLocationViewModel : ViewModel() {

    enum class LocationStatus {
        Current, Center, Move, Search
    }

    var familyId: Long? = null
    var initLocation = true
    var currentCity = ""
    val searchList = ObservableArrayList<AddressModel>()

    val familyLocationLatLngLiveData = MutableLiveData<LatLng>()

    val searchEditLiveData = MutableLiveData<String>()
    val locationTextLiveData = MutableLiveData<String>()
    val searchListShowStatusLiveData = MutableLiveData<Boolean>(false)
    val locationStatusLiveData = MutableLiveData<LocationStatus>()
    val currentLatLngLiveData = MutableLiveData<LatLng>()
    val searchAddressLiveData = MutableLiveData<AddressModel>()

    fun modifyFamilyRoomLocation() = ApiRepository.modifyFamilyLocation(
        FamilyModel(
            id = familyId,
            latitude = familyLocationLatLngLiveData.value!!.latitude,
            longitude = familyLocationLatLngLiveData.value!!.longitude
        )
    )

}